Crate atoi

source · []
Expand description

A crate for parsing integers directly from ASCII ([u8]) without encoding them into utf8 first. The name is inspired by the famous C function.

Using str::from_utf8 and str::parse is likely to be more idiomatic. Use this crate if you want to avoid decoding bytes into utf8 (e.g. for performance reasons).

Note that if you want to know how much of the input has been used, you can use the FromRadix10 trait, for example:

use atoi::FromRadix10;

/// Return the parsed integer and remaining slice if successful.
fn atoi_with_rest<I: FromRadix10>(text: &[u8]) -> ((&[u8], Option<I>)) {
    match I::from_radix_10(text) {
        (_, 0) => (text, None),
        (n, used) => (&text[used..], Some(n)),
    }
}

Enums

Representation of a numerical sign

Traits

Types implementing this trait can be parsed from a positional numeral system with radix 10
Types implementing this trait can be parsed from a positional numeral system with radix 10. Acts much like FromRadix10, but performs additional checks for overflows.
Types implementing this trait can be parsed from a positional numeral system with radix 10. This trait allows for an additional sign character (+ or -) in front of the actual number in order, to allow for parsing negative values.
Types implementing this trait can be parsed from a positional numeral system with radix 10. Acts much like FromRadix10Signed, but performs additional checks for overflows.
Types implementing this trait can be parsed from a positional numeral system with radix 16
Types implementing this trait can be parsed from a positional numeral system with radix 16. Acts much like FromRadix16, but performs additional checks for overflows.
A bounded integer, whose representation can overflow and therefore can only store a maximum number of digits

Functions

Converts an ascii character to digit
Parses an integer from a slice.